<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<script type="text/javascript" src="${ctx}/js/common/utility.js"></script>
	<style type="text/css">

		.panel-tool a.layout-button-up {
			display: none;
		}

		.window .window-body {
			word-wrap: break-word;
		}
	</style>
</head>
<body class="topjui-layout">
<!-- Search panel start -->
<div class="ui-search-panel" style="height:130px;" title="操作框"
     data-options="region:'north',iconCls:'fa fa-search',border:false,split:false">
	<form id="searchForm1">
		<p class="ui-fields" style="min-width:840px">
			<%--	<label class="ui-label">发送方设备号</label><input id="sendSim" name="sendSim" data-toggle="topjui-textbox"
															 style="width:240px;">--%>
			<label class="ui-label">发送方显示名称</label><input id="sendEquipName" name="sendEquipName"
			                                              data-toggle="topjui-textbox"
			                                              style="width:240px;">
			<%--	<label class="ui-label">接收方设备号</label><input id="recSim" name="recSim" data-toggle="topjui-textbox"
															 style="width:240px;">--%>
			<label class="ui-label">接收方显示名称</label><input id="recEquipName" name="recEquipName"
			                                              data-toggle="topjui-textbox"
			                                              style="width:240px;">
			<br>
			<span style="display: block;margin-top: 5px;"></span>
			<label class="ui-label" style="margin-left: 17px;padding-right: 20px;">发送时间</label>
			<input name="startTime" id="startTimeSearch"
			       class="topjui-datetimebox" editable="false"
			       data-options=" width:240">
			<label class="ui-label" style="margin-left: 32px;padding-right: 45px;">至</label>
			<input name="endTime" id="endTimeSearch"
			       class="topjui-datetimebox" editable="false"
			       data-options=" width:240">

			<a href="#" id="btn-search" class="topjui-menubutton" data-options="iconCls:'fa fa-search',
           btnCls:'topjui-btn'" style="margin-left: 35px;">搜索</a>

			<a href="#" id="btn-export" class="topjui-menubutton" data-options="iconCls:'fa fa-cloud-download',
           btnCls:'topjui-btn'" style="margin-left: 5px;">导出</a>
		</p>
	</form>
</div>
<!--  Search panel end -->

<!-- DataList  -->
<div region="center" border="false">
	<table id="data-list"></table>
</div>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript" src="${ctx}/js/common/DataGrid.js"></script>
<script type="text/javascript">
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
	// 例子：
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
	Date.prototype.Format = function (fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}

	$(function () {
		$("#startTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 00:00:00");
		$("#endTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 23:59:59");

		$("#btn-search").click(function () {
			var sendSim = $("#sendSim").val();
			var recSim = $("#recSim").val();
			var sendEquipName = $("#sendEquipName").val();
			var recEquipName = $("#recEquipName").val();
			if (validateDate()) {
				var startTime = $("#startTimeSearch").datetimebox('getText');
				var endTime = $("#endTimeSearch").datetimebox('getText');
				var param = {
					sendSim: sendSim,
					recSim: recSim,
					startTime: startTime,
					endTime: endTime,
					sendEquipName: sendEquipName,
					recEquipName: recEquipName
				};
				$('#data-list').datagrid('reload', param);
			}
		});


		$("#btn-export").click(function () {
			if (validateDate()) {
				var sendEquipName = $("#sendEquipName").val();
				var recEquipName = $("#recEquipName").val();
				var startTime = $("#startTimeSearch").datetimebox('getText');
				var endTime = $("#endTimeSearch").datetimebox('getText');
				//var param = {equipName: equipName, simNo: simNo, startTime: startTime, endTime: endTime};
				var url = '${ctx}/message/exportHisMessage?sendEquipName=' + sendEquipName + '&recEquipName=' + recEquipName + '&startTime=' + startTime + '&endTime=' + endTime + '&dataListForExport=' + true;
				window.location.href = url;
			}
		});
	});


	function validateDate() {
		var startTime = $("#startTimeSearch").datetimebox('getText');
		var endTime = $("#endTimeSearch").datetimebox('getText');
		startTime = Utility.stringToDate(startTime);
		endTime = Utility.stringToDate(endTime);
		if (isNaN(startTime.getTime()) || isNaN(endTime.getTime())) {
			$.iMessager.alert('提示', '非法的日期格式', 'messager-warning');
			return false;
		}
		var today = new Date();

		var date1 = new Date(startTime.getFullYear(), startTime.getMonth(), startTime.getDate());
		var date2 = new Date(endTime.getFullYear(), endTime.getMonth(), endTime.getDate());
		var date3 = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
		if (startTime > today) {
			$.iMessager.alert('提示', '开始日期不能大于当前日期', 'messager-warning');
			return false;
		}
		if (date2 > date3) {
			$.iMessager.alert('提示', '结束日期不能大于今天日期', 'messager-warning');
			return false;
		}
		if (startTime >= endTime) {
			$.iMessager.alert('提示', '开始时间不能大于等于结束时间', 'messager-warning');
			return false;
		}

		var iDays = Utility.getDay(date1, date2);
		if (iDays > 2) {
			$.iMessager.alert('提示', '一次只能操作不超过两天的报文短信数据', 'messager-warning');
			return false;
		}
		return true;
	}


	function detailMessage(content) {
		$.iMessager.alert("详细内容", content);
	}
</script>
<script type="text/javascript" src="${ctx}/js/message/message.js"></script>
</body>
</html>
